<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="keywords" content="{eyou:global name='web_keywords' /}">
    <meta name="description" content="{eyou:global name='web_description' /}">
    <title>{eyou:global name='web_title' /}</title>
    {eyou:include file="import.htm" /}
</head>

<body>
    <div class="container">
        {eyou:include file="header.htm" /}
        <div class="row">
            <div class="col-12">
                <!-- 日历插件 -->
                <table class="table table-bordered text-center mb-4" id="calendar">
                    <thead>
                        <tr>
                            <th class="font-weight-normal" id="c-left" role="button" colspan="2">上一月</th>
                            <th class="font-weight-normal" id="c-center" role="button" colspan="3"></th>
                            <th class="font-weight-normal" id="c-right" role="button" colspan="2">下一月</th>
                        </tr>
                    </thead>
                    <tbody id="c-body"></tbody>
                </table>
                <script>
                    (function () {
                        var cLeft = document.getElementById('c-left');
                        var cCenter = document.getElementById('c-center');
                        var cRight = document.getElementById('c-right');
                        var cBody = document.getElementById('c-body');
                        var month = SolarMonth.fromDate(new Date());
                        generate(month);
                        cLeft.onclick = function () {
                            month = month.next(-1);
                            generate(month);
                        };
                        cCenter.onclick = function () {
                            month = SolarMonth.fromDate(new Date());
                            generate(month);
                        };
                        cRight.onclick = function () {
                            month = month.next(1);
                            generate(month);
                        };
                        function generate(m) {
                            cCenter.innerHTML = m.toFullString();
                            cBody.innerHTML = '<tr><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td><td>日</td></tr><tr class="c-line"></tr>';
                            var cLine = document.getElementsByClassName('c-line');
                            var index = 0;
                            var days = m.getDays();
                            var dayFirst = days[0].getWeek() ? days[0].getWeek() : 7;
                            var dayLast = days[days.length - 1].getWeek();
                            for (var i = dayFirst - 1; i > 0; i--) {
                                var prevText = [];
                                var prevDay = days[0].next(-i).getLunar().getDayInChinese();
                                var prevFestival = days[0].next(-i).getFestivals();
                                var prevLunarFestival = days[0].next(-i).getLunar().getFestivals();
                                var prevHolidays = HolidayUtil.getHoliday(days[0].next(-i).toYmd());
                                var prevSolarTerms = days[0].next(-i).getLunar().getJieQi();
                                if (prevSolarTerms) {
                                    prevText.push(prevSolarTerms);
                                }
                                for (var j = 0; j < prevFestival.length; j++) {
                                    prevText.push(prevFestival[j]);
                                }
                                for (var j = 0; j < prevLunarFestival.length; j++) {
                                    prevText.push(prevLunarFestival[j]);
                                }
                                if (prevHolidays) {
                                    var prevIsWork = (prevHolidays.isWork() ? '<span class="bg-danger">班</span>' : '<span class="bg-success">休</span>');
                                } else {
                                    var prevIsWork = '';
                                }
                                if (prevText.length) {
                                    cLine[0].innerHTML += '<td class="position-relative text-black-40">' + days[0].next(-i).getDay() + '<small class="d-block text-danger-40">' + prevText + '</small>' + prevIsWork + '</td>';
                                } else {
                                    cLine[0].innerHTML += '<td class="position-relative text-black-40">' + days[0].next(-i).getDay() + '<small class="d-block">' + prevDay + '</small>' + prevIsWork + '</td>';
                                }
                            }
                            for (var i = 0; i < days.length; i++) {
                                var text = [];
                                var day = days[i].getDay();
                                var lunarDay = days[i].getLunar().getDayInChinese();
                                var holidays = HolidayUtil.getHoliday(days[i].toYmd());
                                var festival = days[i].getFestivals();
                                var lunarFestival = days[i].getLunar().getFestivals();
                                var solarTerms = days[i].getLunar().getJieQi();
                                if (solarTerms) {
                                    text.push(solarTerms);
                                }
                                for (var j = 0; j < festival.length; j++) {
                                    text.push(festival[j]);
                                }
                                for (var j = 0; j < lunarFestival.length; j++) {
                                    text.push(lunarFestival[j]);
                                }
                                if (text.length) {
                                    lunarDay = '<u class="text-danger text-decoration-none">' + text + '</u>';
                                }
                                if (holidays) {
                                    var isWork = (holidays.isWork() ? '<span class="bg-danger">班</span>' : '<span class="bg-success">休</span>');
                                } else {
                                    var isWork = '';
                                }
                                if (days[i].getWeek() == 1) {
                                    index = index + 1;
                                    cBody.innerHTML += '<tr class="c-line"><td class="position-relative">' + day + '<small class="d-block text-muted">' + lunarDay + '</small>' + isWork + '</td></tr>';
                                } else {
                                    cLine[index].innerHTML += '<td class="position-relative">' + day + '<small class="d-block text-muted">' + lunarDay + '</small>' + isWork + '</td>';
                                }
                                if (new Date().setHours(0, 0, 0, 0) == new Date(days[i].toString()).setHours(0, 0, 0, 0)) {
                                    cBody.getElementsByTagName('td')[i + dayFirst + 6].classList.add('bg-warning');
                                }
                            }
                            for (var i = 1; i < 8 - dayLast; i++) {
                                var nextText = [];
                                var nextDay = days[days.length - 1].next(+i).getLunar().getDayInChinese();
                                var nextFestival = days[days.length - 1].next(+i).getFestivals();
                                var nextLunarFestival = days[days.length - 1].next(+i).getLunar().getFestivals();
                                var nextHolidays = HolidayUtil.getHoliday(days[days.length - 1].next(+i).toYmd());
                                var nextSolarTerms = days[days.length - 1].next(+i).getLunar().getJieQi();
                                if (nextSolarTerms) {
                                    nextText.push(nextSolarTerms);
                                }
                                for (var j = 0; j < nextFestival.length; j++) {
                                    nextText.push(nextFestival[j]);
                                }
                                for (var j = 0; j < nextLunarFestival.length; j++) {
                                    nextText.push(nextLunarFestival[j]);
                                }
                                if (nextHolidays) {
                                    var nextIsWork = (nextHolidays.isWork() ? '<span class="bg-danger">班</span>' : '<span class="bg-success">休</span>');
                                } else {
                                    var nextIsWork = '';
                                }
                                if (dayLast) {
                                    if (nextText.length) {
                                        cLine[index].innerHTML += '<td class="position-relative text-black-40">' + days[days.length - 1].next(+i).getDay() + '<small class="d-block text-danger-40">' + nextText + '</small>' + nextIsWork + '</td>';
                                    } else {
                                        cLine[index].innerHTML += '<td class="position-relative text-black-40">' + days[days.length - 1].next(+i).getDay() + '<small class="d-block">' + nextDay + '</small>' + nextIsWork + '</td>';
                                    }
                                }
                            }
                        }
                    })();
                </script>
            </div>
        </div>
    </div>
    <!-- 返回顶部 -->
    <button type="button" class="to-top btn bg-dark text-white"><i class="bi bi-chevron-up"></i></button>
    <script>
        $(document).ready(function () {
            $('.to-top').toTop({
                autohide: true,
                offset: 420,
                speed: 400,
                position: true,
                right: 15,
                bottom: 30
            });
        });
    </script>
</body>

</html>